<template>
    <div>
     <div class="table-page-search-wrapper">
      <p-form layout="inline">
        <p-row :gutter="24">
           <p-col :span="6">
               <p-form-item label="供应商编码">
                   <p-input v-model="query.supno" placeholder="请输入供应商编码"></p-input>
               </p-form-item>
           </p-col>
           <p-col :span="6" >
               <p-form-item label="供应商名称">
                   <p-input v-model="query.supname" placeholder="请输入供应商名称"></p-input>
               </p-form-item>
           </p-col>
           <p-col :span="6">
               <p-form-item>
                   <p-button type="primary" @click="searchOk">查询</p-button>
               </p-form-item>
           </p-col>
        </p-row>
      </p-form>
    </div>

     <p-table
     :columns="columns"
     :pagination="ipagination"
     :selection="onSelection"
     :row-selection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange,onSelect:onseChange }"
     :dataSource="dataList"
     @change="handleTableChange">
     </p-table>
     <section slot="footer" style="text-align:right;">
        <p-button style="margin-right:10px;">取消</p-button>
        <p-button type="primary" @click="submitHandle">确认</p-button>
     </section>
    </div>
</template>

<script>
import { getActionBasic, getAction, deleteAction, downFile } from '@/api/manage';
import pick from 'lodash.pick'
export default {
    data() {
        return { 
           url:{
             getColumns:'/basic-business/online/cgreport/api/getRpColumns/ba_supinfo', //供应商codeId
             list:'/basic-business/online/cgreport/api/getColumnsAndData/'
           },
           query:{},
           ipagination:{
            current: 1,
            pageSize: 10,
            pageSizeOptions: ['10', '20', '50'],
            showTotal: (total, range) => {
                return range[0] + "-" + range[1] + " 共" + total + "条"
            },
            showQuickJumper: true,
            showSizeChanger: true,
            total: 0
            },
           reSuCode:'',
           columns:[],
           selectedList:[],
           selectedRowKeys:[],
        };
    },
    created() {
    },
    mounted() {
     this.initColums()
    },
    methods: {
        submitHandle(){
            this.$emit('sumitOk',this.selectedList)
        },
        onSelectChange(val,row){
            console.log(val)
            this.selectedRowKeys = val
            // this.selectedList = row
        },
        onseChange(row,isAs,c,d){
            if(isAs){
              this.selectedList.push(row)
            }else{
              this.selectedList.map((item,i)=>{
                if(row.supid === item.supid){
                  this.selectedList.splice(i,1)
                }
              })
            }
            console.log('iiiiiiiiiii',this.selectedList)
        },
        selection(row){
            console.log(row)
        },
        handleTableChange(pagination, filters, sorter) {
        this.ipagination = pagination
        const info ={
            limit:this.ipagination.pageSize,
            pageNo:this.ipagination.current
        }
        this.initDataList(this.reSuCode,info)
        },
        searchOk(){
        //   const obj = pick(this.query,'supno','supname')
        let info = {}
        if(this.query.supno ==='' && this.query.supname ===''){
           info = Object.assign({},{limit:10,pageNo:1})
        }else if(this.query.supno ==='' && this.query.supname ===null){
           info = Object.assign({},{limit:10,pageNo:1})
        }else if(this.query.supno ===null && this.query.supname ===''){
           info = Object.assign({},{limit:10,pageNo:1})
        }else{
           info = Object.assign(this.query,{limit:10,pageNo:1})
        }
          this.initDataList(this.reSuCode,info)
        },
        //code码
        initColums(){
            getActionBasic(this.url.getColumns).then(res=>{
                if(res.code === 0){
                 this.reSuCode = res.data.cgRpConfigId   
                 this.columns = res.data.columns
                 this.ipagination.current = 1
                 this.initDataList(this.reSuCode,{limit:10,pageNo:1})
                }
            })
        },
        initDataList(code,params){
            console.log(this.reSuCode)
            getAction(this.url.list+code,params).then(res=>{
                if(res.code === 0){
                    this.dataList = res.data.data.records || []
                    this.dataList.map(item=>{
                        item.key = item.supid
                    })
                    this.columns = res.data.columns || []
                    this.ipagination.total = res.data.data.total || 0
                }
            })
        }
    }
};
</script>

<style scoped lang="less">

</style>
